package com.igorkundovic.guitarstab.pages;

import java.util.List;

import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.CleanupRender;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.igorkundovic.guitarstab.Artist;
import com.igorkundovic.guitarstab.Tab;
import com.igorkundovic.guitarstab.User;
import com.igorkundovic.guitarstab.beans.ArtistBean;
import com.igorkundovic.guitarstab.beans.TabBean;
import com.igorkundovic.guitarstab.service.TabService;

public class SearchSong {

	@ApplicationState
	@Property
	private User user;
	private boolean userExists;
	@Inject
	private TabService tabservice;	
	@Property
	@Persist
	private List<Tab> tabs;
	@Property 
	private TabBean tabbean;
	@Property
    private String message;
	@Property
	private Artist artist;
	@Property
	@Persist
	private String message2;
	
	public Object onActivate(){
		if(userExists){
			return null;
		}
		return Welcome.class;
	}
	
	@SetupRender
	public void setUp(){
		
	}
	
	public Object onSuccess(){
		tabs=null;
		artist=new ArtistBean();
		artist.setSongName(message);
		tabs=tabservice.searchByArtist(artist, "name");
		if(tabs.isEmpty()){
			message2="Sorry, there is no song that matches that input...";
		}
		return this;
	}
	 
	@CleanupRender
	public void cleanUp(){
		tabs=null;
		message2=null;
		}
}
